#define _CRT_SECURE_NO_WARNINGS 1


#include<string>
#include<iostream>

using namespace std;

int main()
{
	int arr[26] = { 0 };
	for (int i = 0; i < 26; i++)
	{
		arr[i] = i + 1;
	}
	string s1, s2;
	cin >> s1 >> s2;
	int sum1 = 1, sum2 = 1;
	for (auto& e : s1)
	{
		sum1 *= arr[e - 'A'];
	}

	for (auto& e : s2)
	{
		sum2 *= arr[e - 'A'];
	}

	if (sum1 % 47 == sum2 % 47)
	{
		cout << "GO" << endl;
	}
	else
	{
		cout << "STAY" << endl;
	}

	return 0;
}